<?php
!defined('IN_SYSTEM') && exit('Access denied');
class class_excel 
{
	public static function export_csv($data,$cell)
	{
		$filename = date('YmdHis').".csv";
		header("Content-type:text/csv");
		header("Content-Disposition:attachment;filename=".$filename);
		header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
		header('Expires:0');
		header('Pragma:public');
		echo class_excel::array_to_string($data,$cell);
	}

	/**
	 *导出数据转换
	 * @param $result
	 */
	public static function array_to_string($result,$cell)
	{
		if(empty($result))
		{
			return i("没有符合您要求的数据！");
		}
		$size_result = sizeof($result);
		for($i = 0 ; $i < $size_result ;  $i++)
		{
			foreach((array)$cell as $val)
			{
				$data.= i($result[$i][$val]).',';
			}
			$data = rtrim($data, ",");
			$data.= "\n";
		}
		return $data;
	}
	
	
	public static function ImportCsv()
	{
		$filesname = $_FILES['upfile']['name'];
		$attach_ext = strtolower(substr(strrchr($filesname,'.'),1));
		if($attach_ext == 'csv' )
		{
			 $data = file($_FILES['upfile']['tmp_name']);
			 return $data;
		}
		return false;
	}
}
?>